package com.home.oss.factory;

import com.home.common.utils.string.StringUtils;
import com.home.oss.config.FileConfig;
import com.home.oss.constants.OssUploadConstant;
import com.home.oss.service.LocalUploadServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Description: 文件上传工厂
 * Created by 王大宸 on 2020-10-15 21:34
 * Created with IntelliJ IDEA.
 */
@Component
public class FileFactory {
    private static final Logger logger = LoggerFactory.getLogger(FileFactory.class);
    @Autowired
    private FileConfig fileConfig;

    public FileFactoryServer build() {
        String type = fileConfig.getType();
        // 如果没有配置上传目标服务,这里默认上传为本地
        if (StringUtils.isEmpty(type)) {
            type = OssUploadConstant.TYPE_LOCAL;
        }
        // 本地上传
        if (OssUploadConstant.TYPE_LOCAL.equals(type)) {
            return new LocalUploadServer();
        }
        return null;
    }

}
